package com.weijian.dto.data;

import lombok.Data;

import java.math.BigDecimal;

/**
 * 批次统计信息DTO
 */
@Data
public class BatchStatistics {
    /**
     * 路线数量
     */
    private Long routeCount;

    /**
     * 货物数量
     */
    private Long shipmentCount;

    /**
     * 已匹配货物数量
     */
    private Long matchedCount;

    /**
     * 未匹配货物数量
     */
    private Long unmatchedShipments;

    /**
     * 路线利用率（百分比）
     */
    private Double routeUtilization;

    /**
     * 匹配成功率（百分比）
     */
    private Double matchRate;

    public BatchStatistics() {
        this.routeCount = 0L;
        this.shipmentCount = 0L;
        this.matchedCount = 0L;
        this.unmatchedShipments = 0L;
        this.routeUtilization = 0.0;
        this.matchRate = 0.0;
    }

    public BatchStatistics(Long routeCount, Long shipmentCount) {
        this.routeCount = routeCount != null ? routeCount : 0L;
        this.shipmentCount = shipmentCount != null ? shipmentCount : 0L;
        this.matchedCount = 0L;
        this.unmatchedShipments = this.shipmentCount;
        this.routeUtilization = 0.0;
        this.matchRate = 0.0;
    }

    /**
     * 计算衍生统计数据
     */
    public void calculateDerivedStats() {
        // 计算未匹配货物数量
        if (this.unmatchedShipments == null) {
            this.unmatchedShipments = this.shipmentCount - (this.matchedCount != null ? this.matchedCount : 0L);
        }

        // 计算匹配成功率
        if (this.matchRate == null && this.shipmentCount > 0) {
            this.matchRate = this.matchedCount != null ?
                    BigDecimal.valueOf(this.matchedCount * 100.0 / this.shipmentCount).doubleValue() : 0.0;
        }
    }
}